#!/usr/bin/python
import sys , re
sys.path.append("../classes")
from logger import *
from db import *
logger = Logger("../logs")
logger.setVerbose()

###################################################################

print "Connecting and retrieving time references from Mysql..."

conf = {"seconds_offset" : 2 * 24 * 60 * 60 , "seconds_range" : 60 , 'table':'searches_last_30_days' ,
        'host':'localhost' , 'port':'3306' ,  'db':'bi_dev' , 'user':'ohad','password':'ohad1961' , 'rdbms':'mysql' ,'time_field':'datetime'}

d = DB(conf, logger)
if d.connect() and d.time_ref():
#        print d.ranges
#        print d.times_ref
	print "asserting 4 timestamps ..."
	assert(re.match(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}' , d.times_ref[0]) and len(d.times_ref) == 4)
	print "OK"
else:
	print "Connection Problem"
	sys.exit(1)

###################################################################	

print "Connecting and retrieving time references from Redshift using postgresql sql..."

conf = {"seconds_offset" : 2 * 24 * 60 * 60 , "seconds_range" : 120 , 'table':'searches_last_30_days' ,
        'host':'redshift01.infra-team.com' , 'port':'5439'  ,'db':'icbi' , 'user':'icbi','password':'UAx9O7kg49:5^Y5' , 'rdbms':'postgresql' ,'time_field':'datetime'}

d = DB(conf, logger)
if d.connect() and d.time_ref():
#        print d.ranges
#        print d.times_ref
        print "asserting 4 timestamps ..."
        assert(re.match(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}' , d.times_ref[0]) and len(d.times_ref) == 4)
        print "OK"
else:
        print "Connection Problem"
        sys.exit(1)

###################################################################


